#ifndef QHCONTROLLERFORM_H
#define QHCONTROLLERFORM_H

#include <QWidget>
#include <QPainter>
#include <QMouseEvent>

namespace Ui {
class QhControllerForm;
}

class QhControllerForm : public QWidget
{
    Q_OBJECT

public:
    explicit QhControllerForm(QWidget *parent = nullptr);
    ~QhControllerForm();

signals:
    void sig_directionKeyPressed(int direction); // 0:上 1:左 2:下 3:右 4：中 5：无

protected:
    void paintEvent(QPaintEvent *event) override;
    void mousePressEvent(QMouseEvent *event) override;
    void mouseReleaseEvent(QMouseEvent *event) override;

private:
    Ui::QhControllerForm *ui;
    bool isPointInCir(const QPoint &point, const QRect &rect);
    QRectF drawRect;//整个大圆的范围
    QPainterPath fanShaped[4];
    QRectF centerCircularRect;//中心圆按钮的范围

    QPainterPath gradientArc(double startAngle, double angleLength, double arcHeight);

    enum class PressBtnType //按下的是哪个按钮
    {
        up = 0,
        left,
        down,
        right,
        center,
        None
    };
    PressBtnType m_pressedBtn{PressBtnType::None};
};

#endif // QHCONTROLLERFORM_H
